﻿@using LeadMaster.Models
@model IEnumerable<LeadMaster.Models.Diary>

<img src="~/Images/create.png" class="creatediary navbuttons boxtitle" />
<label class="boxtitle">Diary Schedule</label>

<table class="listtable contactstable" cellspacing="0" cellpadding="0">
    <tr>
        <th class="tableheader">Complete</th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.ContactID)
        </th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.CompanyID)
        </th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.Notes)
        </th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.ContactType)
        </th>
        <th class="tableheader">
            @Html.DisplayNameFor(model => model.Scheduled)
        </th>
    </tr>

@foreach (Diary item in Model)
{
    <tr 
    @if(item.Scheduled.ToShortDateString()==DateTime.Now.ToShortDateString())
    {
        @:style="color: #FF0000; text-decoration: blink"   
    }
    >
        <td>
        @if (item.Completed == null)
        {
        <img src="../../Images/tick.png" style="cursor: pointer" id="complete@(item.DiaryID)" class="completeschedule"/>    
        }
        else
        {
        @:&nbsp;
        }
        </td>
        <td>
            <label>
            @item.Contact.Forename @item.Contact.Surname
            </label>
        </td>
        <td>
            <label>
                @item.Contact.Company.Company
            </label>
        </td>
        <td class="showNote" id="note@(item.DiaryID)" style="cursor: pointer">
            <label style="cursor: pointer">
            @{string subNotes = item.Notes.Substring(0, item.Notes.Trim().Length > 100 ? 100 : item.Notes.Trim().Length);
              @subNotes
            }
            </label>
            <input type="hidden" name="hdnNote" id="hdnNote@(item.DiaryID)" value="@(item.Notes)" />
        </td>
        <td>
        <label>
        @{
              switch (item.ContactType)
              {
              case "E":
                <text>
                Email
                </text>
                break;
              case "T":
                <text>
                Telephone
                </text>
                break;
              case "M":
                <text>
                Meeting
                </text>
                break;
              case "O":
                <text>
                Other
                </text>
                break;
              case "S":
                <text>
                Skype
                </text>
                break;
              case "N":
                <text>
                Netmeeting
                </text>
                break;
              }
        }
        </label>
        </td>
        <td>
            <label>
            @item.Scheduled.ToShortDateString()
            @item.Scheduled.ToShortTimeString()
            </label>
        </td>
    </tr>
}

</table>

<div id="notesdialog" class="overlay">
@Html.TextArea("notecontents", new { id = "notecontents", @class = "largenotes", @readonly = "true" })
</div>

<div id="creatediarydialog" class="overlay" title="Add New Lead">
</div>

<script type="text/javascript">
    $(document).ready(function () {

        $("#notesdialog").dialog({
            autoOpen: false,
            width: 735,
            open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
            show: {
                effect: "blind",
                duration: 1000
            },
            hide: {
                effect: "explode",
                duration: 1000
            }
        });

        $(".showNote").click(function () {
            var id = $(this).attr('id').substring(4);
            $('#notecontents').val($("#hdnNote" + id).val());
            $("#notesdialog").dialog("open");
        });

        $(".completeschedule").click(function () {
            var id = $(this).attr('id').substring(8);
            $('#diarylist').load('@(Url.Action("CompleteSchedule", "Diary"))/' + id);
        });

        $("#creatediary").click(function () {
            var id = 0;
            $("#creatediarydialog").html('<div style="text-align: center;"><div><img src="@Url.Content("~/Images/ajaxspinner_large.gif")" alt="Loading..." style="margin: 20px;" /></div><div>Loading...</div></div>');
            $('#creatediarydialog').load('@(Url.Action("Create", "Diary"))/' + id,
                function () {
                    $("#creatediarydialog").dialog("close");
                    $("#creatediarydialog").dialog(
                    {
                        autoOpen: true,
                        width: 900,
                        open: function () { $(".ui-dialog").css("box-shadow", "#000 5px 5px 5px"); },
                        position: { my: 'center', at: 'center', of: window },
                        modal: true,
                        resizable: false,
                        draggable: false,
                        dialogClass: 'notitle'
                    });
                });
                $("#creatediarydialog").dialog(
                {
                    autoOpen: true,
                    width: 200,
                    position: { my: 'center', at: 'center', of: window },
                    modal: true,
                    resizable: false,
                    draggable: false,
                    dialogClass: 'notitle'
                });
        });

    });
</script>
